/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.spreedairy.portal.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import com.spreedairy.portal.service.CustomFieldValueLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Proxy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author SpreeDairy
 */
public class CustomFieldValueClp extends BaseModelImpl<CustomFieldValue>
	implements CustomFieldValue {
	public CustomFieldValueClp() {
	}

	public Class<?> getModelClass() {
		return CustomFieldValue.class;
	}

	public String getModelClassName() {
		return CustomFieldValue.class.getName();
	}

	public long getPrimaryKey() {
		return _recId;
	}

	public void setPrimaryKey(long primaryKey) {
		setRecId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_recId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("recId", getRecId());
		attributes.put("itemId", getItemId());
		attributes.put("keyName", getKeyName());
		attributes.put("keyValue", getKeyValue());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long recId = (Long)attributes.get("recId");

		if (recId != null) {
			setRecId(recId);
		}

		Long itemId = (Long)attributes.get("itemId");

		if (itemId != null) {
			setItemId(itemId);
		}

		String keyName = (String)attributes.get("keyName");

		if (keyName != null) {
			setKeyName(keyName);
		}

		String keyValue = (String)attributes.get("keyValue");

		if (keyValue != null) {
			setKeyValue(keyValue);
		}
	}

	public long getRecId() {
		return _recId;
	}

	public void setRecId(long recId) {
		_recId = recId;
	}

	public long getItemId() {
		return _itemId;
	}

	public void setItemId(long itemId) {
		_itemId = itemId;
	}

	public String getKeyName() {
		return _keyName;
	}

	public void setKeyName(String keyName) {
		_keyName = keyName;
	}

	public String getKeyValue() {
		return _keyValue;
	}

	public void setKeyValue(String keyValue) {
		_keyValue = keyValue;
	}

	public BaseModel<?> getCustomFieldValueRemoteModel() {
		return _customFieldValueRemoteModel;
	}

	public void setCustomFieldValueRemoteModel(
		BaseModel<?> customFieldValueRemoteModel) {
		_customFieldValueRemoteModel = customFieldValueRemoteModel;
	}

	public void persist() throws SystemException {
		if (this.isNew()) {
			CustomFieldValueLocalServiceUtil.addCustomFieldValue(this);
		}
		else {
			CustomFieldValueLocalServiceUtil.updateCustomFieldValue(this);
		}
	}

	@Override
	public CustomFieldValue toEscapedModel() {
		return (CustomFieldValue)Proxy.newProxyInstance(CustomFieldValue.class.getClassLoader(),
			new Class[] { CustomFieldValue.class },
			new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		CustomFieldValueClp clone = new CustomFieldValueClp();

		clone.setRecId(getRecId());
		clone.setItemId(getItemId());
		clone.setKeyName(getKeyName());
		clone.setKeyValue(getKeyValue());

		return clone;
	}

	public int compareTo(CustomFieldValue customFieldValue) {
		long primaryKey = customFieldValue.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		CustomFieldValueClp customFieldValue = null;

		try {
			customFieldValue = (CustomFieldValueClp)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = customFieldValue.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(9);

		sb.append("{recId=");
		sb.append(getRecId());
		sb.append(", itemId=");
		sb.append(getItemId());
		sb.append(", keyName=");
		sb.append(getKeyName());
		sb.append(", keyValue=");
		sb.append(getKeyValue());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(16);

		sb.append("<model><model-name>");
		sb.append("com.spreedairy.portal.model.CustomFieldValue");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>recId</column-name><column-value><![CDATA[");
		sb.append(getRecId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>itemId</column-name><column-value><![CDATA[");
		sb.append(getItemId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>keyName</column-name><column-value><![CDATA[");
		sb.append(getKeyName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>keyValue</column-name><column-value><![CDATA[");
		sb.append(getKeyValue());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _recId;
	private long _itemId;
	private String _keyName;
	private String _keyValue;
	private BaseModel<?> _customFieldValueRemoteModel;
}